﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace _016_线程问题_争用条件
{
    class Program
    {
        static void Change(object obj)
        {
            MyThreadObject m = obj as MyThreadObject;
            while (true)
            {
                lock (m)
                {
                    m.ChangeState();
                }
                
            }
        }

        static void Main(string[] args)
        {
            MyThreadObject obj = new MyThreadObject();
            TaskFactory tf = new TaskFactory();
            tf.StartNew(Change, obj);
            tf.StartNew(Change, obj);
            tf.StartNew(Change, obj);

            Console.ReadKey();
        }
    }
}
